A pager implementing the free list pattern. More...
Public Member Functions | |
FreeListPager (size_t pageSize) | |
~FreeListPager ()=default | |
size_t | getPageSize () const |
size_t | getAllocatedPageCount () const |
const FreeListMemorySpaceWrapper< T, U > & | getPage (size_t index) |
FreeListAllocation< T > | allocate (size_t size, size_t alignment=1) |
void | free (size_t allocationIndex) |
A pager implementing the free list pattern.
This pattern keeps track of allocations within the pages, and returns allocations fitting the requirements within the memory space allocated. Allocations can be freed individually. This pager can be used when data will be kept around, with no knowledge about the lifetime of it.
For instance, in a 3d renderer, gpu resources can be placed within a memory space as they come and go, reducing the need for memory allocations.
nkMemory::FreeListPager< T, U >::FreeListPager | ( | size_t | pageSize | ) |
Constructor.
pageSize | The size to use for pages. |
|
default |
Destructor.
size_t nkMemory::FreeListPager< T, U >::getPageSize | ( | ) | const |
size_t nkMemory::FreeListPager< T, U >::getAllocatedPageCount | ( | ) | const |
const FreeListMemorySpaceWrapper<T, U>& nkMemory::FreeListPager< T, U >::getPage | ( | size_t | index | ) |
FreeListAllocation<T> nkMemory::FreeListPager< T, U >::allocate | ( | size_t | size, |
size_t | alignment = 1 |
||
) |
Requests an allocation.
size | The size of the allocation needed. |
alignment | The needed alignment in the memory space. |
void nkMemory::FreeListPager< T, U >::free | ( | size_t | allocationIndex | ) |
Releases an allocation so that it returns within the pager.
allocationIndex | The index for the allocation to free. Provided by allocate(). |